package com.mxx.common.flow;

import com.mxx.common.spring.ApplicationContextHelper;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Supplier;

/**
 * @author: mxx
 * @date: 2021/12/30
 * @time: 11:51
 * @Description: 描述信息
 */
public class FlowModule {

    protected List<Supplier<Flow>> flowFactoryList;

    protected FlowEvent activeEvent;

    public FlowModule(FlowEvent activeEvent) {
        this.activeEvent = activeEvent;
        this.flowFactoryList = new ArrayList<>();
    }

    public <C extends Flow> FlowModule addMultiple(Class<C> classes) {
        flowFactoryList.add(() -> ApplicationContextHelper.createBean(classes));
        return this;
    }

    public <C extends Flow> FlowModule addSingle(C c) {
        flowFactoryList.add(() -> c);
        return this;
    }


    public Flows newFlows() {
        List<Flow> flowList = new ArrayList<>();
        for (Supplier<Flow> supplier : flowFactoryList) {
            flowList.add(supplier.get());
        }
        Flows flows = new Flows(flowList);
        return flows;
    }

    public FlowEvent getActive() {
        return this.activeEvent;
    }

}
